using System;
using System.Windows.Controls;

namespace WikiApp.Services
{
    public class NavigationService
    {
        private static Frame? _mainFrame;
        private static NavigationService? _instance;

        private NavigationService() { }

        public static NavigationService Instance
        {
            get
            {
                _instance ??= new NavigationService();
                return _instance;
            }
        }

        public void Initialize(Frame mainFrame)
        {
            _mainFrame = mainFrame ?? throw new ArgumentNullException(nameof(mainFrame));
        }

        public void NavigateTo(Page page)
        {
            if (_mainFrame == null)
                throw new InvalidOperationException("NavigationService not initialized");

            _mainFrame.Navigate(page);
        }

        public void GoBack()
        {
            if (_mainFrame == null)
                throw new InvalidOperationException("NavigationService not initialized");

            if (_mainFrame.CanGoBack)
                _mainFrame.GoBack();
        }

        public bool CanGoBack => _mainFrame?.CanGoBack ?? false;
    }
} 